<template>
    <div>
        <div v-if="dataSource.length > 0">
            <a-table :dataSource="dataSource" :pagination="false" bordered>
                <a-table-column key="stashId" title="仓库id" data-index="stashId" />
                <a-table-column key="stashName" title="仓库名称" data-index="stashName" />
                <a-table-column key="stashTotalCapacity" title="仓库总容量（理论面积）" data-index="stashTotalCapacity" />
                <a-table-column key="stashCapacity" title="仓库以使用容量" data-index="stashCapacity" />
                <a-table-column title="操作">
                    <template #default="{ record }">
                        <a-button type="text" @click="Echarts(record.stashId)">数据可视化</a-button>
                        <a-button type="text" @click="See(record.stashId)">查询详情</a-button>
                    </template>
                </a-table-column>
            </a-table>

        </div>
        <div v-else>
            <a-empty description="暂无数据">
            </a-empty>
        </div>


    </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import { useRouter } from "vue-router";
import { StashSelectAll } from "../../Axios/Admin";
import { area } from "../../utils/unit";
const router = useRouter()
let dataSource = ref([{
    stashId: 0,
    stashName: "",
    stashTotalCapacity: "",
    stashCapacity: "",
}])
let ListDate = ref([{
    stashId: 0,
    stashName: "",
    stashTotalCapacity: 0,
    stashCapacity: 0,
}])


onMounted(async () => {
    await init()
})

const Echarts = (num) => {

    router.push({
        name: "StashECharts",
        query: {
            id: num
        }
    })
}
const See = (num) => {

    router.push({
        name: "IndexDetils",
        query: {
            id: num
        }
    })
}





const init = async () => {
    const res = await StashSelectAll()
    if (res && res.code == 200) {
        if (res.data) {
            ListDate.value = res.data
            dataSource.value = res.data

            for (let index = 0; index < ListDate.value.length; index++) {
                // const element = array[index];
                dataSource.value[index].stashId = ListDate.value[index].stashId
                dataSource.value[index].stashName = ListDate.value[index].stashName
                dataSource.value[index].stashTotalCapacity = area(ListDate.value[index].stashTotalCapacity)
                dataSource.value[index].stashCapacity = area(ListDate.value[index].stashCapacity)

            }

        }


    }
}
</script>

<style lang="scss" scoped>
.EditBox {


    .EditBoxP {

        .EditBoxPSpan {
            color: red;
        }
    }
}
</style>